package deng.camel.beans.processors;

import java.util.Map;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MessageHeaderAdder implements Processor {

	private static Log logger = LogFactory.getLog(MessageHeaderAdder.class);

	private Map<String, Object> headers;
	
	public void setHeaders(Map<String, Object> headers) {
		this.headers = headers;
	}

	@Override
	public void process(Exchange exchange) throws Exception {
		Message msg = exchange.getIn();
		String id = msg.getMessageId();
		for (Map.Entry<String, Object> e : headers.entrySet()) {
			String key = e.getKey();
			Object value = e.getValue();
			logger.info("Adding message header: key=" + ", value=" + value + " to msg.id=" + id);
			msg.setHeader(key, value);
		}
		exchange.setOut(msg);
	}
	
}
